package WebRoot.usdemo;

import java.util.HashMap;
import java.util.Map;

import org.hoyi.DB.CLuster.DataBaseCluster;
import org.hoyi.DB.Interface.IDatabase;
import org.hoyi.dishop.Hoyipage;
import org.hoyi.district.DistrictCtrls;
import org.hoyi.util.DateTimeUtil;
import org.hoyi.util.GetMD5pwd;

import model.users;

/**
 * Android测试DEMO.
 * @author ellen
 * 
 *
 */
public class usService extends Hoyipage{

	public void Register() {
		
		String username = this.getParams("username");
		String pwds = this.getParams("pwds");
		
		IDatabase _dDatabase = DistrictCtrls.get_Insert_DB("user", users.class);
		
		String md5pwds = GetMD5pwd.getPassMD5(pwds);
		users _users = new users(_dDatabase.Get_Clust_UUID(), username, "1", DateTimeUtil.getCurrentDateTime(), md5pwds);
		
		int ret = _users.Insert(_dDatabase);
		this.HandlerEx("注册用户", ret);
	}
	
	
	public void Login() {
		String username = this.getParams("username");
		// 本地要加密再传上来，
		// 这里解密后再做MD5解密处理.
		String pwds = this.getParams("pwds");

		String md5pwds = GetMD5pwd.getPassMD5(pwds);
		
		// 每个区的满足条件的条数.
		Map<String, Long> cfil_counts = new HashMap<String, Long>();
		
		for (String clus_keys : DataBaseCluster.clusters.get("user").keySet()) {
			IDatabase _tdb = DataBaseCluster.Get_WRITE_SERVER("user", clus_keys);

			boolean exists = users.E().Where(users.username.Equals(username).AND(users.notes.Equals(md5pwds))).Exists(_tdb);
			if(exists) {
				// 这里注册用户并生成TOKEN.
				this.HandlerEx("登录", 1);	
			}
		}
		this.HandlerEx("登录", -1);
		
		
	}
	
	
}
